# pip install zhipuai 请先在终端进行安装
import os

from zhipuai import ZhipuAI

client = ZhipuAI(api_key=os.environ["ZHIPU_API_KEY"])

response = client.chat.completions.create(
    model="glm-4v",
    messages=[
        # {
        #     "role": "user",
        #     "content": [{"type": "text", "text": "图片里有什么东西？"},
        #                 {"type": "image_url", "image_url": {
        #                     "url": "https://img2.baidu.com/it/u=3557838069,1126397164&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=375"}}
        #                 ]
        # },
        {
            "role": "user",
            "content": [{"type": "text", "text": "图片里有什么东西？"},
                        {"type": "image_url", "image_url": {
                            "url": "https://lablab.ai/_next/image?url=https%3A%2F%2Fstorage.googleapis.com%2Flablab-static-eu%2Fimages%2Fevents%2Fclv2h2zf7000c357g4dtk3g89%2Fundefined_imageLink_lk8u20gm3.jpg&w=1080&q=75"}}
                        ]
        }
    ],
    top_p=0.7,
    temperature=0.95,
    max_tokens=1024,
    stream=True,
)
for trunk in response:
    print(trunk.choices[0].delta.content, end="")
